package com.xyhuo.leetcode.december;

/**
 * 删除有序数组中的重复项
 * https://leetcode.cn/problems/remove-duplicates-from-sorted-array/
 *
 * @time 2023/12/12
 */
public class RemoveDuplicates {

//    public static void main(String[] args) {
//        RemoveDuplicates rd = new RemoveDuplicates();
//        int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
//        rd.removeDuplicates(nums);
//    }

    public int removeDuplicates(int[] nums) {
        int len = nums.length;
        int left = 0, right = 1;
        while (true) {
            if (right >= len) {
                break;
            }
            if (nums[left] != nums[right]) {
                nums[left + 1] = nums[right];
                left++;
            }
            right++;
        }
        return left + 1;
    }
}
